/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mlbs.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author mckd87
 */
@Entity
@Table(name = "usersession")
@NamedQueries({@NamedQuery(name = "Usersession.findById", query = "SELECT u FROM Usersession u WHERE u.id = :id"), @NamedQuery(name = "Usersession.findBySession", query = "SELECT u FROM Usersession u WHERE u.session = :session"), @NamedQuery(name = "Usersession.findByLastlogin", query = "SELECT u FROM Usersession u WHERE u.lastlogin = :lastlogin")})
public class Usersession implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "session")
    private String session;
    @Column(name = "lastlogin", nullable = false)
    @Temporal(TemporalType.DATE)
    private Date lastlogin;
    @JoinColumn(name = "id", referencedColumnName = "id", insertable = false, updatable = false)
    @OneToOne
    private Credential credential;

    public Usersession() {
    }

    public Usersession(Integer id) {
        this.id = id;
    }

    public Usersession(Integer id, Date lastlogin) {
        this.id = id;
        this.lastlogin = lastlogin;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getSession() {
        return session;
    }

    public void setSession(String session) {
        this.session = session;
    }

    public Date getLastlogin() {
        return lastlogin;
    }

    public void setLastlogin(Date lastlogin) {
        this.lastlogin = lastlogin;
    }

    public Credential getCredential() {
        return credential;
    }

    public void setCredential(Credential credential) {
        this.credential = credential;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Usersession)) {
            return false;
        }
        Usersession other = (Usersession) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mlbs.entity.Usersession[id=" + id + "]";
    }

}
